import React from 'react';
import { Tree } from 'antd';
import type { DataNode, DirectoryTreeProps } from 'antd/es/tree';
import store from '@/redux/store.js'
import {changeCheckTree} from '@/redux/actions'

const { DirectoryTree } = Tree;
const TreeArea = (props:DataNode[]) => {
  const treeData = props?.data || []
  const onSelect: DirectoryTreeProps['onSelect'] = (keys, info) => {
    // console.log('Trigger Select', keys, info);
    store.dispatch(changeCheckTree(keys[0]))
  };

  const onExpand: DirectoryTreeProps['onExpand'] = (keys, info) => {
    // console.log('Trigger Expand', keys, info);

  };

  return (
    treeData.length>0 &&
    <DirectoryTree
      multiple
      defaultExpandAll
      onSelect={onSelect}
      onExpand={onExpand}
      treeData={treeData}
    />
  );
};

export default TreeArea;
